package com.food.controller;

import com.food.common.Result;
import com.food.dto.MealRecordDTO;
import com.food.model.MealRecord;
import com.food.service.MealRecordService;
import com.food.util.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Api(tags = "膳食记录管理")
@RestController
@RequestMapping("/api/meal-records")
public class MealRecordController {

    @Autowired
    private MealRecordService mealRecordService;

    @ApiOperation("添加膳食记录")
    @PostMapping
    public Result<?> addMealRecord(
            @RequestParam Integer userId,
            @RequestBody MealRecordDTO mealRecordDTO) {
        return mealRecordService.addMealRecord(userId, mealRecordDTO);
    }

    @ApiOperation("获取每日膳食记录")
    @GetMapping("/daily")
    public Result<List<MealRecord>> getDailyRecords(
            @RequestParam Integer userId,
            @ApiParam(value = "日期", example = "2024-01-15")
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date) {
        return Result.success(mealRecordService.getDailyRecords(userId, date));
    }

    @ApiOperation("删除膳食记录")
    @DeleteMapping("/{recordId}")
    public Result<?> deleteMealRecord(
            @RequestParam Integer userId,
            @ApiParam(value = "记录ID", required = true, example = "1")
            @PathVariable Integer recordId) {
        return mealRecordService.deleteMealRecord(userId, recordId);
    }
} 